package com.renren.project.core.rulehandler.handler;


import com.renren.project.core.rulehandler.entity.Rule;
import com.renren.project.core.rulehandler.entity.NationalityRuleDto;
import com.renren.project.core.rulehandler.RuleConstant;
/**
 * @author liyang
 * @version 1.0.0
 * @ClassName NationalityRule
 * @Description 具体规则- 例子2
 * @createTime 21:26:00 2021/08/22
 */
public class NationalityRule extends AbstractRule{

    @Override
    protected <T> T convert(Rule rule) {
        NationalityRuleDto nationalityRuleDto = new NationalityRuleDto();
        if (rule.getAddress().startsWith(RuleConstant.MATCH_ADDRESS_START)) {
            nationalityRuleDto.setNationality(RuleConstant.MATCH_NATIONALITY_START);
        }
        return (T) nationalityRuleDto;
    }


    @Override
    protected <T> boolean executeRule(T t) {
        System.out.println("NationalityRule invoke!");
        NationalityRuleDto nationalityRuleDto = (NationalityRuleDto) t;
        if (nationalityRuleDto.getNationality().startsWith(RuleConstant.MATCH_NATIONALITY_START)) {
            return true;
        }
        return false;
    }
}
